home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 2990 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1014 b   |  42 lines

  1. Path: news.dx.net!news
  2. From: erowe@bayou.com
  3. Newsgroups: comp.lang.c++
  4. Subject: Reading File with Structure Problem
  5. Date: Sun, 21 Jan 96 03:01:14 GMT
  6. Organization: The DataXchange Network, Inc
  7. Message-ID: <N.012096.210114.91@mail>
  8. NNTP-Posting-Host: 199.190.112.30
  9. X-Newsreader: Quarterdeck Message Center [1.0]
  10.  
  11. I am having difficulty reading in a file into a structure.  The file's contents 
  12. is "123456789John Doe", but try as I may I cannot get "123456789" into the ssn 
  13. variable, nor can I get "John Doe" into the name variable. 8-(  Any insights 
  14. greatly appreciated...below is my source:
  15.  
  16. #include <iostream.h>
  17. #include <fstream.h>
  18.  
  19. void main(void)
  20. {
  21.  
  22.  struct gradebook {
  23.    char ssn[10];
  24.    char name[10];
  25.  }  student;
  26.  
  27.    ifstream student_file("test.dat");
  28.  
  29.    student_file.read((char *) &student, sizeof(gradebook));
  30.  
  31.    cout << "SSN" << student.ssn << endl;
  32.    cout << "Name" << student.name << endl;
  33. }
  34.  
  35. //test.dat is a file that contains the following (w/o a return character)
  36. //123456789john doe
  37.  
  38.  
  39.  
  40.  
  41.  
  42.